package com.superdp.config;

import com.superdp.utils.LoginInterceptor;
import com.superdp.utils.RefreshTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * ClassName: InterceptorConfig
 * Package: com.superdp.config
 * Description:
 *
 * @Author: XKing
 * @Create: 2023/6/30 - 15:46
 * @Version: 1.0
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Resource
    StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * token刷新拦截器
         */
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).order(0);

        /**
         * 登录拦截器，放行部分不需要登录的请求。
         */
        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns(
                "/shop/**",
                "/voucher/**",
                "/shop-type/**",
                "/upload/**",
                "/blog/hot",
                "/user/login",
                "/user/code"
        ).order(1);
    }


}
